package com.zfjt.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.ReturnBean;
import com.zfjt.entity.UserBean;
import com.zfjt.packnum.PackNum00031;
import com.zfjt.service.UserService;

/**
 * 获取个人资料
 * @author xk
 * @version 1.0
 * @date 2017年3月30日
 */
@Controller
public class PersonalDataController {

	@Autowired
	private UserService mUser;
	
	private ReturnBean mReturn;
	
	private Map<String, String> fhdata;
	
	@RequestMapping(value="00031")
	@ResponseBody
	public ReturnBean Login(HttpSession hseesion){
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00031 no00031 = JSON.parseObject(data,PackNum00031.class);
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {
			mReturn.setCode("001");
			mReturn.setPortnum("00031");
			fhdata.put("error", "TOKEN_ERROR");
			String fh = JSON.toJSONString(fhdata);
			mReturn.setData(fh);
		}else{
			UserBean user = mUser.selectByPrimaryKey(no00031.getAccount());
			fhdata.put("name", user.getName());
			fhdata.put("type", user.getType());
			fhdata.put("money", user.getMoney());
			fhdata.put("mobile", user.getMobile());
			fhdata.put("head", user.getHead());
			fhdata.put("branch", user.getYuliu());
			fhdata.put("news", user.getNews());
			mReturn.setCode("000");
			mReturn.setPortnum("00031");
			mReturn.setData(JSON.toJSONString(fhdata));
		}
		return mReturn;
	}
}
